import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-09-28
 * Time:22:55
 */

/**
 * 力扣剑指offer03.数组中的重复数字
 */

public class findRepeatNumber {
    public int findRepeatNumber(int[] nums) {
//        for (int i = 0; i < nums.length; i++) {
//            for (int j = i+1; j < nums.length; j++) {
//                if (nums[i] == nums[j]){
//                    return nums[i];
//                }
//            }
//        }
//        return -1;
        Set<Integer> dic = new HashSet<>();
        for(int num : nums) {
            if(dic.contains(num)) return num;
            dic.add(num);
        }
        return -1;
    }
}
